/**
 * Created by ZYK on 2019/7/17.
 */
function regexMatch(number) {
    var reg = /^[-\+]?\d+(\.\d+)?$/;
    number = !reg.test(number) ? 0 : number;
    return number;
}
//非空
function bigNotNull(big,scale){
    var result = new BigDecimal("0");
    result = new BigDecimal(regexMatch(big).toString());
    result = result.setScale(scale,BigDecimal.prototype.ROUND_HALF_UP);
    return result;
}

//相乘
function bigMulBigByArea(big1,big2,scale){
    var result = new BigDecimal("0");
    big1 = new BigDecimal(regexMatch(big1).toString());
    big2 = new BigDecimal(regexMatch(big2).toString());
    result = big1.multiply(big2);
    result = result.setScale(scale,BigDecimal.prototype.ROUND_HALF_UP);
    return result;
}

//相加
function bigAddBig(big1,big2,scale){
    var result = new BigDecimal("0");
    big1 = new BigDecimal(regexMatch(big1).toString());
    big2 = new BigDecimal(regexMatch(big2).toString());
    result = big1.add(big2);
    result = result.setScale(scale,BigDecimal.prototype.ROUND_HALF_UP);
    return result;
}

//相减
function bigSubBig(big1,big2,scale){
    var result = new BigDecimal("0");
    big1 = new BigDecimal(regexMatch(big1).toString());
    big2 = new BigDecimal(regexMatch(big2).toString());
    result = big1.subtract(big2);
    result = result.setScale(scale,BigDecimal.prototype.ROUND_HALF_UP);
    return result;
}

//相除
function bigDivBig(big1,big2,scale){
    var result = new BigDecimal("0");
    big1 = new BigDecimal(regexMatch(big1).toString());
    big2 = new BigDecimal(regexMatch(big2).toString());
    if (big2.compareTo(new BigDecimal("0")) > 0){
        result = big1.divide(big2,scale,BigDecimal.prototype.ROUND_HALF_UP);
    }
    return result;
}